home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK2.toast / Development Kits / QuickTime / QuickTime 3 Interfaces & Libs / QTDevWin / CIncludes / DigitalSignature.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-21  |  16.8 KB  |  397 lines  |  [TEXT/dosa]

  1. /*
  2.      File:        DigitalSignature.h
  3.  
  4.      Contains:    Digital Signature Interfaces.
  5.  
  6.      Version:    Technology:    AOCE toolbox 1.02
  7.                  Release:    QuickTime 3.0
  8.  
  9.      Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __DIGITALSIGNATURE__
  19. #define __DIGITALSIGNATURE__
  20.  
  21. #ifndef __MACTYPES__
  22. #include <MacTypes.h>
  23. #endif
  24. #ifndef __MIXEDMODE__
  25. #include <MixedMode.h>
  26. #endif
  27. #ifndef __FILES__
  28. #include <Files.h>
  29. #endif
  30.  
  31.  
  32.  
  33. #if PRAGMA_ONCE
  34. #pragma once
  35. #endif
  36.  
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40.  
  41. #if PRAGMA_IMPORT
  42. #pragma import on
  43. #endif
  44.  
  45. #if PRAGMA_STRUCT_ALIGN
  46.     #pragma options align=mac68k
  47. #elif PRAGMA_STRUCT_PACKPUSH
  48.     #pragma pack(push, 2)
  49. #elif PRAGMA_STRUCT_PACK
  50.     #pragma pack(2)
  51. #endif
  52.  
  53. /* values of SIGNameAttributeType */
  54.  
  55. enum {
  56.     kSIGCountryCode                = 0,
  57.     kSIGOrganization            = 1,
  58.     kSIGStreetAddress            = 2,
  59.     kSIGState                    = 3,
  60.     kSIGLocality                = 4,
  61.     kSIGCommonName                = 5,
  62.     kSIGTitle                    = 6,
  63.     kSIGOrganizationUnit        = 7,
  64.     kSIGPostalCode                = 8
  65. };
  66.  
  67. typedef unsigned short                     SIGNameAttributeType;
  68. /* 
  69. Certificate status codes returned in SIGCertInfo or SIGSignerInfo from
  70. either SIGGetCertInfo or SIGGetSignerInfo respectively. kSIGValid means that
  71. the certificate is currently valid. kSIGPending means the certificate is
  72. currently not valid - but will be.  kSIGExpired means the certificate has
  73. expired. A time is always associated with a SIGCertStatus.  In each case the
  74. time has a specific interpretation.  When the status is kSIGValid the time is
  75. when the certificate will expire. When the status is kSIGPending the time is
  76. when the certificate will become valid. When the status is kSIGExpired the time
  77. is when the certificate expired. In the SIGCertInfo structure, the startDate
  78. and endDate fields hold the appropriate date information.  In the SIGSignerInfo
  79. structure, this information is provided in the certSetStatusTime field. In the
  80. SIGSignerInfo struct, the status time is actually represented by the SIGSignatureStatus
  81. field which can contain any of the types below. NOTE: The only time you will get 
  82. a kSIGInvalid status is when it pertains to a SIGSignatureStatus field and only when
  83. you get a signature that was created after the certificates expiration date, something
  84. we are not allowing on the Mac but that may not be restricted on other platforms. Also, 
  85. it will not be possible to get a kSIGPending value for SIGSignatureStatus on the Mac but
  86. possibly allowed by other platforms.
  87. */
  88. /* Values for SIGCertStatus or SIGSignatureStatus */
  89.  
  90. enum {
  91.     kSIGValid                    = 0,                            /* possible for either a SIGCertStatus or SIGSignatureStatus */
  92.     kSIGPending                    = 1,                            /* possible for either a SIGCertStatus or SIGSignatureStatus */
  93.     kSIGExpired                    = 2,                            /* possible for either a SIGCertStatus or SIGSignatureStatus * possible only for a SIGSignatureStatus */
  94.     kSIGInvalid                    = 3
  95. };
  96.  
  97. typedef unsigned short                     SIGCertStatus;
  98. typedef unsigned short                     SIGSignatureStatus;
  99. /* Number of bytes needed for a digest record when using SIGDigest */
  100.  
  101. enum {
  102.     kSIGDigestSize                = 16
  103. };
  104.  
  105. typedef Byte                             SIGDigestData[16];
  106. typedef Byte *                            SIGDigestDataPtr;
  107.  
  108. struct SIGCertInfo {
  109.     unsigned long                     startDate;                    /* cert start validity date */
  110.     unsigned long                     endDate;                    /* cert end validity date */
  111.     SIGCertStatus                     certStatus;                    /* see comment on SIGCertStatus for definition */
  112.     unsigned long                     certAttributeCount;            /* number of name attributes in this cert */
  113.     unsigned long                     issuerAttributeCount;        /* number of name attributes in this certs issuer */
  114.     Str255                             serialNumber;                /* cert serial number */
  115. };
  116. typedef struct SIGCertInfo                SIGCertInfo;
  117. typedef SIGCertInfo *                    SIGCertInfoPtr;
  118.  
  119. struct SIGSignerInfo {
  120.     unsigned long                     signingTime;                /* time of signing */
  121.     unsigned long                     certCount;                    /* number of certificates in the cert set */
  122.     unsigned long                     certSetStatusTime;            /* Worst cert status time. See comment on SIGCertStatus for definition */
  123.     SIGSignatureStatus                 signatureStatus;            /* The status of the signature. See comment on SIGCertStatus for definition*/
  124. };
  125. typedef struct SIGSignerInfo            SIGSignerInfo;
  126. typedef SIGSignerInfo *                    SIGSignerInfoPtr;
  127.  
  128. struct SIGNameAttributesInfo {
  129.     Boolean                         onNewLevel;
  130.     Boolean                         filler1;
  131.     SIGNameAttributeType             attributeType;
  132.     ScriptCode                         attributeScript;
  133.     Str255                             attribute;
  134. };
  135. typedef struct SIGNameAttributesInfo    SIGNameAttributesInfo;
  136. typedef SIGNameAttributesInfo *            SIGNameAttributesInfoPtr;
  137.  
  138. typedef Ptr                             SIGContextPtr;
  139. typedef Ptr                             SIGSignaturePtr;
  140. /*
  141. Certificates are always in order. That is, the signers cert is always 0, the
  142. issuer of the signers cert is always 1 etc… to the number of certificates-1.
  143. You can use this constant for readability in your code.
  144. */
  145.  
  146. enum {
  147.     kSIGSignerCertIndex            = 0
  148. };
  149.  
  150. /*
  151. Call back procedure supplied by developer, return false to cancel the current
  152. process.
  153. */
  154. typedef CALLBACK_API( Boolean , SIGStatusProcPtr )(void );
  155. typedef STACK_UPP_TYPE(SIGStatusProcPtr)                         SIGStatusUPP;
  156. enum { uppSIGStatusProcInfo = 0x00000010 };                     /* pascal 1_byte Func() */
  157. #define NewSIGStatusProc(userRoutine)                             (SIGStatusUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSIGStatusProcInfo, GetCurrentArchitecture())
  158. #define CallSIGStatusProc(userRoutine)                             CALL_ZERO_PARAMETER_UPP((userRoutine), uppSIGStatusProcInfo)
  159. /*
  160. Resource id's of standard signature icon suite, all sizes and colors are available.
  161. */
  162.  
  163. enum {
  164.     kSIGSignatureIconResID        = -16797,
  165.     kSIGValidSignatureIconResID    = -16799,
  166.     kSIGInvalidSignatureIconResID = -16798
  167. };
  168.  
  169. /* ——————————————————————————————— CONTEXT CALLS ——————————————————————————————— 
  170. To use the Digital Signature toolbox you will need a SIGContextPtr.  To create
  171. a SIGContextPtr you simply call SIGNewContext and it will create and initialize
  172. a context for you.  To free the memory occupied by the context and invalidate
  173. its internal data, call SIGDisposeContext. An initialized context has no notion
  174. of the type of operation it will be performing however, once you call
  175. SIGSignPrepare SIGVerifyPrepare, or SIGDigestPrepare, the contexts operation
  176. type is set and to switch  to another type of operation will require creating a
  177. new context. Be sure to pass the same context to corresponding toolbox calls
  178. (ie SIGSignPrepare, SIGProcessData, SIGSign)  in other words mixing lets say
  179. signing and verify calls with the same context is not allowed.
  180. */
  181. EXTERN_API( OSErr )
  182. SIGNewContext                    (SIGContextPtr *        context)                            FOURWORDINLINE(0x203C, 0x0002, 0x076C, 0xAA5D);
  183.  
  184. EXTERN_API( OSErr )
  185. SIGDisposeContext                (SIGContextPtr             context)                            FOURWORDINLINE(0x203C, 0x0002, 0x076D, 0xAA5D);
  186.  
  187.  
  188. /* ——————————————————————————————— SIGNING CALLS ——————————————————————————————— 
  189. Once you have created a SIGContextPtr, you create a signature by calling
  190. SIGSignPrepare once, followed by n calls to SIGProcessData, followed by one call
  191. toRcpt SIGSign. To create another signature on different data but for the same
  192. signer, don't dispose of the context and call SIGProcessData for the new data
  193. followed by a call SIGSign again. In this case the signer will not be prompted
  194. for their signer and password again as it was already provided.  Once you call
  195. SIGDisposeContext, all signer information will be cleared out of the context and
  196. the signer will be re-prompted.  The signer file FSSpecPtr should be set to nil
  197. if you want the toolbox to use the last signer by default or prompt for a signer
  198. if none exists.  The prompt parameter can be used to pass a string to be displayed
  199. in the dialog that prompts the user for their password.  If the substring "^1"
  200. (without the quotes) is in the prompt string, then the toolbox will replace it
  201. with the name of the signer from the signer selected by the user.  If an empty
  202. string is passed, the following default string will be sent to the toolbox
  203. "\pSigning as ^1.".  You can call any of the utility routines after SIGSignPrepare
  204. or SIGSign to get information about the signer or certs.
  205. */
  206. EXTERN_API( OSErr )
  207. SIGSignPrepare                    (SIGContextPtr             context,
  208.                                  const FSSpec *            signerFile,
  209.                                  ConstStr255Param         prompt,
  210.                                  Size *                    signatureSize)                        FOURWORDINLINE(0x203C, 0x0008, 0x076E, 0xAA5D);
  211.  
  212. EXTERN_API( OSErr )
  213. SIGSign                            (SIGContextPtr             context,
  214.                                  SIGSignaturePtr         signature,
  215.                                  SIGStatusProcPtr         statusProc)                            FOURWORDINLINE(0x203C, 0x0006, 0x076F, 0xAA5D);
  216.  
  217.  
  218. /* ——————————————————————————————— VERIFYING CALLS ——————————————————————————————— 
  219. Once you have created a SIGContextPtr, you verify a signature by calling
  220. SIGVerifyPrepare  once, followed by n calls to SIGProcessData, followed by one
  221. call to SIGVerify. Check the return code from SIGVerify to see if the signature
  222. verified or not (noErr is returned on  success otherwise the appropriate error
  223. code).  Upon successfull verification, you can call any of the utility routines
  224. toRcpt find out who signed the data.
  225. */
  226. EXTERN_API( OSErr )
  227. SIGVerifyPrepare                (SIGContextPtr             context,
  228.                                  SIGSignaturePtr         signature,
  229.                                  Size                     signatureSize,
  230.                                  SIGStatusProcPtr         statusProc)                            FOURWORDINLINE(0x203C, 0x0008, 0x0770, 0xAA5D);
  231.  
  232. EXTERN_API( OSErr )
  233. SIGVerify                        (SIGContextPtr             context)                            FOURWORDINLINE(0x203C, 0x0002, 0x0771, 0xAA5D);
  234.  
  235. /* —————————————————————————————— DIGESTING CALLS —————————————————————————————— 
  236. Once you have created a SIGContextPtr, you create a digest by calling
  237. SIGDigestPrepare once, followed by n calls to SIGProcessData, followed by one
  238. call to SIGDigest.  You can dispose of the context after SIGDigest as the
  239. SIGDigestData does not reference back into it.  SIGDigest returns the digest in
  240. digest.
  241. */
  242. EXTERN_API( OSErr )
  243. SIGDigestPrepare                (SIGContextPtr             context)                            FOURWORDINLINE(0x203C, 0x0002, 0x0772, 0xAA5D);
  244.  
  245. EXTERN_API( OSErr )
  246. SIGDigest                        (SIGContextPtr             context,
  247.                                  SIGDigestData             digest)                                FOURWORDINLINE(0x203C, 0x0004, 0x0773, 0xAA5D);
  248.  
  249.  
  250. /* —————————————————————————————— PROCESSING DATA —————————————————————————————— 
  251. To process data during a digest, sign, or verify operation call SIGProcessData
  252. as many times as necessary and with any sized blocks of data.  The data needs to
  253. be processed in the same order during corresponding sign and verify operations
  254. but does not need to be processed in the same sized chunks (i.e., the toolbox
  255. just sees it as a continuous bit stream).
  256. */
  257. EXTERN_API( OSErr )
  258. SIGProcessData                    (SIGContextPtr             context,
  259.                                  const void *            data,
  260.                                  Size                     dataSize)                            FOURWORDINLINE(0x203C, 0x0006, 0x0774, 0xAA5D);
  261.  
  262.  
  263. /* ——————————————————————————————— UTILITY CALLS ——————————————————————————————— 
  264. Given a context that has successfully performed a verification SIGShowSigner
  265. will  display a modal dialog with the entire distinguished name of the person
  266. who signed the data. the prompt (if supplied) will appear at the top of the
  267. dialog.  If no prompt is specified, the default prompt "\pVerification
  268. Successfull." will appear.
  269.  
  270. Given a context that has been populated by calling SIGSignPrepare, SIGSign or a
  271. successful SIGVerify, you can make the remaining utility calls:
  272.  
  273. SIGGetSignerInfo will return the SignerInfo record.  The certCount can be used
  274. toRcpt index into the certificate set when calling SIGGetCertInfo,
  275. SIGGetCertNameAttributes or SIGGetCertIssuerNameAttributes. The signingTime is
  276. only defined if the call is made after SIGSign  or SIGVerify. The certSetStatus
  277. will tell you the best status of the entire certificate set while
  278. certSetStatusTime will correspond to the time associated with that status (see
  279. definitions above).
  280.  
  281. SIGGetCertInfo will return the SIGCertInfo record when given a valid index into
  282. the cert set in  certIndex.  Note: The cert at index kSIGSignerCertIndex is
  283. always the signers certificate.  The  serial number, start date and end date
  284. are there should you wish to display that info.  The  certAttributeCount and
  285. issuerAttributeCount provide the number of parts in the name of that certificate
  286. or that certificates issuer respectively.  You use these numbers to index into
  287. either SIGGetCertNameAttributes or SIGGetCertIssuerNameAttributes to retrieve
  288. the name. The certStatus will tell you the status of the certificate while
  289. certStatusTime will correspond to the time associated with that status (see
  290. definitions above).
  291.  
  292. SIGGetCertNameAttributes and SIGGetCertIssuerNameAttributes return name parts
  293. of the certificate at  certIndex and attributeIndex.  The newLevel return value
  294. tells you wether the name attribute returned is at the same level in the name
  295. hierarchy as the previous attribute.  The type return value tells you  the type
  296. of attribute returned. nameAttribute is the actual string containing the name
  297. attribute.   So, if you wanted to display the entire distinguished name of the
  298. person who's signature was just validated you could do something like this;
  299.  
  300.     (…… variable declarations and verification code would preceed this sample ……)
  301.  
  302.     error = SIGGetCertInfo(verifyContext, kSIGSignerCertIndex, &certInfo);
  303.     HandleErr(error);
  304.  
  305.     for (i = 0; i <= certInfo.certAttributeCount-1; i++)
  306.         {
  307.         error = SIGGetCertNameAttributes(
  308.             verifyContext, kSIGSignerCertIndex, i, &newLevel, &type, theAttribute);
  309.         HandleErr(error);
  310.         DisplayNamePart(theAttribute, type, newLevel);
  311.         }
  312. */
  313. EXTERN_API( OSErr )
  314. SIGShowSigner                    (SIGContextPtr             context,
  315.                                  ConstStr255Param         prompt)                                FOURWORDINLINE(0x203C, 0x0004, 0x0775, 0xAA5D);
  316.  
  317. EXTERN_API( OSErr )
  318. SIGGetSignerInfo                (SIGContextPtr             context,
  319.                                  SIGSignerInfo *        signerInfo)                            FOURWORDINLINE(0x203C, 0x0004, 0x0776, 0xAA5D);
  320.  
  321. EXTERN_API( OSErr )
  322. SIGGetCertInfo                    (SIGContextPtr             context,
  323.                                  unsigned long             certIndex,
  324.                                  SIGCertInfo *            certInfo)                            FOURWORDINLINE(0x203C, 0x0006, 0x0777, 0xAA5D);
  325.  
  326. EXTERN_API( OSErr )
  327. SIGGetCertNameAttributes        (SIGContextPtr             context,
  328.                                  unsigned long             certIndex,
  329.                                  unsigned long             attributeIndex,
  330.                                  SIGNameAttributesInfo * attributeInfo)                        FOURWORDINLINE(0x203C, 0x0008, 0x0778, 0xAA5D);
  331.  
  332. EXTERN_API( OSErr )
  333. SIGGetCertIssuerNameAttributes    (SIGContextPtr             context,
  334.                                  unsigned long             certIndex,
  335.                                  unsigned long             attributeIndex,
  336.                                  SIGNameAttributesInfo * attributeInfo)                        FOURWORDINLINE(0x203C, 0x0008, 0x0779, 0xAA5D);
  337.  
  338.  
  339.  
  340. /* ——————————————————————————— FILE SIGN & VERIFY CALLS —————————————————————————— 
  341. These calls allow you to detect the presence of a standard signtaure in a file as 
  342. well as sign and verify files in a standard way.  An example of this is the Finder, 
  343. which uses these calls to allow the user to "drop sign" a file.
  344.  
  345. To detect if a file is signed in the standard way, pass the FSSpec of the file to SIGFileIsSigned.
  346. A result of noErr means the file is in fact signed, otherwise, a kSIGNoSignature error will
  347. be returned.
  348.  
  349. Once you have created a SIGContextPtr, you can make calls to either sign or verify a file in
  350. a standard way: 
  351.  
  352. To sign a file, call SIGSignPrepare followed by 'n' number of calls to SIGSignFile,
  353. passing it the file spec for each file you wish to sign in turn.  You supply the context, the signature 
  354. size that was returned from SIGSignPrepare and an optional call back proc.  The call will take care of all
  355. the processing of data and affixing the signature to the file. If a signature already exists in the file, 
  356. it is replaced with the newly created signature.
  357.  
  358. To verify a file that was signed using SIGSignFile, call SIGVerifyFile passing it a new context and 
  359. the file spec.  Once this call has completed, if the verification is successfull, you can pass the context 
  360. to SIGShowSigner to display the name of the person who signed the file.
  361. */
  362. EXTERN_API( OSErr )
  363. SIGFileIsSigned                    (const FSSpec *            fileSpec)                            FOURWORDINLINE(0x203C, 0x0002, 0x09C4, 0xAA5D);
  364.  
  365. EXTERN_API( OSErr )
  366. SIGSignFile                        (SIGContextPtr             context,
  367.                                  Size                     signatureSize,
  368.                                  const FSSpec *            fileSpec,
  369.                                  SIGStatusProcPtr         statusProc)                            FOURWORDINLINE(0x203C, 0x0008, 0x09C5, 0xAA5D);
  370.  
  371. EXTERN_API( OSErr )
  372. SIGVerifyFile                    (SIGContextPtr             context,
  373.                                  const FSSpec *            fileSpec,
  374.                                  SIGStatusProcPtr         statusProc)                            FOURWORDINLINE(0x203C, 0x0006, 0x09C6, 0xAA5D);
  375.  
  376.  
  377. #if PRAGMA_STRUCT_ALIGN
  378.     #pragma options align=reset
  379. #elif PRAGMA_STRUCT_PACKPUSH
  380.     #pragma pack(pop)
  381. #elif PRAGMA_STRUCT_PACK
  382.     #pragma pack()
  383. #endif
  384.  
  385. #ifdef PRAGMA_IMPORT_OFF
  386. #pragma import off
  387. #elif PRAGMA_IMPORT
  388. #pragma import reset
  389. #endif
  390.  
  391. #ifdef __cplusplus
  392. }
  393. #endif
  394.  
  395. #endif /* __DIGITALSIGNATURE__ */
  396.  
  397.